home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13872 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help:what is wrong this code?
  5. Date: 10 Apr 1996 11:15:12 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4kg580$1ga@sparcserver.lrz-muenchen.de>
  9. References: <4k3p3q$n76@brahms.udel.edu> <4k4hi3$5hm@sparcserver.lrz-muenchen.de> <Pine.ULT.3.92.960409210416.383A-100000@henson.cc.wwu.edu>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Norma Mathews <n9341884@henson.cc.wwu.edu> writes:
  13.  
  14. >On 6 Apr 1996, Kurt Watzka wrote:
  15.  
  16. >> yuehong@brahms.udel.edu (Yue-hong Zheng) writes:
  17. >>
  18. >>
  19. >> >Why it give me 0.0000?
  20. >>
  21. >> >#include <stdio.h>
  22. >> >main () {
  23. >> >double a=9.008;
  24. >> >printf("%f\n",sqrt(a));
  25. >> >return 0;
  26. >> >}
  27.  
  28. >your printf specifer needs to be "%lf", not "%f", since a is a double
  29.  
  30. If it were a call to scanf(), the format string for _scanning_ a 
  31. formatted double would indeed be "%lf". The format string for
  32. printing either a float or a double _is_ "%f". floats and doubles
  33. are both converted to double when passed to a variadic function.
  34.  
  35. So, as long as Yue-hong Zheng is using an ANSI C compiler, the
  36. problem is _not_ that "%f" is used to print a double.
  37.  
  38. Kurt
  39. -- 
  40. | Kurt Watzka                             Phone : +49-89-2180-6254
  41. | watzka@stat.uni-muenchen.de
  42.  
  43.